<template>
	<div class="view">
		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.userName" placeholder="请输入要查询的用户名"></el-input>
			</el-col>
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()">搜索</el-button>
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加用户</el-button>
				<!-- <el-button type="warning" icon="el-icon-delete" plain @click="batchdel()">批量删除</el-button> -->
			</el-col>
		</el-row>
		
		<el-table :data="result.tableData" class="eltable" 
		style="width: 99%;font-size: 12px;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)"
		 @selection-change="handleSelectionChange">
			<!-- <el-table-column
        type="selection"
      >
      </el-table-column> -->
			<el-table-column label="序号" width="40" prop="goId">
			</el-table-column>
			<el-table-column width="60" label="姓名" prop="userName">
			</el-table-column>
			<el-table-column width="30" label="性别" prop="sex">
			</el-table-column>
			<el-table-column width="40" label="年龄" prop="age">
			</el-table-column>
			<el-table-column width="120" label="档案号" prop="fileNum">
			</el-table-column>
			<el-table-column width="80" label="入住时间" prop="startTime">
			</el-table-column>
			<el-table-column width="90" label="退住时间" prop="endTime">
			</el-table-column>
			<el-table-column width="90" label="退住类型" prop="exitType">
			</el-table-column>
			<el-table-column width="90" label="退住原因" prop="exitCause">
			</el-table-column>
			<el-table-column width="60" label="状态" prop="status">
			</el-table-column>
			<el-table-column width="80" label="申请时间" prop="requestTime">
			</el-table-column>
			<el-table-column width="50" label="审核意见" prop="auditOpinion">
			</el-table-column>
			<el-table-column width="50" label="审核人" prop="auditor">
			</el-table-column>
			<el-table-column label="审核时间" prop="auditTime">
			</el-table-column>
			<el-table-column label="备注" prop="note">
			</el-table-column>
	
			<el-table-column label="操作" width="220px">
				<template slot-scope="scope">
					<template v-if="scope.row.status=='待审批'">
						<el-button size="mini" @click="handleEdit(scope.row.exitId)">编辑</el-button>
						<!-- <el-button type="primary" size="mini" @click="handleApproval(scope.row.exitId)">审批</el-button> -->
						<!-- <el-button size="mini" type="danger" @click="handleDelete(scope.row.exitId)">删除</el-button> -->
					</template>
					<template v-else >
						<el-button size="mini" type="info" plain disabled>已审批</el-button>
					</template>
				</template>
				
			</el-table-column>
		</el-table>
		
		<el-pagination style="margin-top:10px;" background layout="prev, pager, next" :page-count="result.pages"
		 :current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<ExitRegistrationEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid"></ExitRegistrationEdit>
		</el-dialog>
		
		<el-dialog :title="title" :visible.sync="appShow" :close-on-click-modal="false" width="500px">
			<ApprovalEdit v-if="appShow" :appShow.sync="appShow" @getData="getData()" :editid="editid"></ApprovalEdit>
		</el-dialog>
	</div>
</template>

<script>
	import ExitRegistrationEdit from '@/views/exit_registration/edit.vue'
	import ApprovalEdit from '@/views/exit_registration/approval_edit'
	export default {
		name: 'ex',
		data() {
			return {
				search: {
					userName: ''
				},
				query: {
					userName: '',
					current: 1,
					size: 5
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				appShow:false,
				editid: null,
				selectedrow: [],
				title: ''
			}
		},
		components: {
			ExitRegistrationEdit,
			ApprovalEdit
		},
		created() {
			this.getData()
			// console.log(this.getData())
		},
		methods: {
			getData() {
				this.axios.get('/exitRegistration/list', response => {
					// console.log(this.query.pageNo)
					// console.log(response.obj.total)
					// this.query.pageNo=response.obj.current
					this.result.tableData = response.obj.records
					this.result.pages = response.obj.pages

				}, this.query)
			},
			searchData() {
				// console.log(this.search)
				this.query.userName = this.search.userName
				console.log(this.search.userName)
				this.query.current = 1
				this.getData()
			},
			handleEdit(id) {
				this.title = '修改用户'
				this.editid = id
				this.show = true
			},
			add() {
				this.title = '添加用户'
				this.editid = null
				this.show = true
			},
			handleDelete(id) {
				this.axios.del('/exitRegistration/del/' + id, response => {
					this.getData()
				}, {
					id: id
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
			handleApproval(id){
				this.title='审批'
				this.editid=id
				this.appShow=true
			}
			// batchdel() {
			//   if(this.selectedrow.length === 0) {
			//     this.$message('没有任何被选中的数据');
			//   } else {
			//     const ids = []
			//     for(let i = 0; i < this.selectedrow.length; i++) {
			//       ids.push(this.selectedrow[i].id)
			//     }
			//     this.axios.del('/use/batchdel',response => {
			//       this.getData()
			//     },{ ids: ids })
			//   }
			// }
			// handleBack(id) {
			//   this.axios.del('/ums-user/back',response => {
			//     this.getData()
			//   }, { id: id }, 'back')
			// },
			// gorole(id) {
			//   this.$router.push({
			//     path: '/user-role',
			//     query:{
			//       id: id
			//     }
			//   })
			// }
		}
	}
</script>
<style scoped>
	.view {
		font-size: 12px;

	}

	.eltable {
		width: 20px;
		padding: 0px;
	}

	.el-table-column {}
</style>
